//
// Created by Administrator on 2023/8/1.
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


class Solution {
public:
    int findNonMinOrMax(vector<int> &nums) {
        if (nums.size() < 3) return -1;
        // 找到nums的最大最小值
        int max = *max_element(nums.begin(), nums.end());
        int min = *min_element(nums.begin(), nums.end());
        for (auto x: nums) {
            if (x != max && x != min) return x;
        }
        return -1;
    }

};
class Solution2 {
public:
    int findNonMinOrMax(vector<int> &nums) {
        if (nums.size() < 3) return -1;
        sort(nums.begin(), nums.begin() + 3); // 只对前三个数排序
        return nums[1];
    }
};



int main(int argc, const char *argv[]) {
    Solution s;
    vector<int> nums = {1, 2};
    cout << s.findNonMinOrMax(nums) << endl;

    return 0;
}